// Kony

#pragma once

#include "CoreMinimal.h"
#include "UI/Widget/BaseUserWidget.h"
#include "GlobeBarWidget.generated.h"

/**
 * 幽灵血球/法力球控件
 * 专门处理幽灵血球和法力球的显示逻辑
 * 支持缓慢跟随和立即恢复两种模式
 * 
 * 使用方法：
 * 1. 在蓝图中创建继承自GlobeBarWidget的UI控件
 * 2. 在蓝图的Tick事件中调用GetCurrentGhostHealthPercent()和GetCurrentGhostManaPercent()来更新进度条
 * 3. 在持续恢复效果开始时调用SetGhostHealthBarFollowing(false)禁用跟随
 * 4. 在持续恢复效果结束时调用SetGhostHealthBarFollowing(true)重新启用跟随
 * 
 * 示例蓝图逻辑：
 * - 在Tick中：ProgressBar->SetPercent(GetCurrentGhostHealthPercent())
 * - 在恢复效果开始时：SetGhostHealthBarFollowing(false)
 * - 在恢复效果结束时：SetGhostHealthBarFollowing(true)
 */
UCLASS()
class GASC_HUANLING_API UGlobeBarWidget : public UBaseUserWidget
{
	GENERATED_BODY()

public:
	UGlobeBarWidget();

protected:
	virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override;
	virtual void NativeConstruct() override;

	//幽灵血球跟随控制 - 静态函数，蓝图可直接调用
	//当为true时，幽灵血球不会跟随当前生命值变化（用于持续恢复效果）
	//当为false时，幽灵血球会正常跟随当前生命值变化（用于受伤效果）
	UFUNCTION(BlueprintCallable, Category = "Ghost Health Bar")
	static void SetGhostHealthBarFollowing(bool bEnableFollowing);
	
	UFUNCTION(BlueprintCallable, Category = "Ghost Health Bar")
	static bool IsGhostHealthBarFollowing();

	//幽灵法力球跟随控制
	UFUNCTION(BlueprintCallable, Category = "Ghost Mana Bar")
	static void SetGhostManaBarFollowing(bool bEnableFollowing);
	
	UFUNCTION(BlueprintCallable, Category = "Ghost Mana Bar")
	static bool IsGhostManaBarFollowing();

	//蓝图可调用的UI更新函数
	UFUNCTION(BlueprintCallable, Category = "Ghost Bar UI")
	float GetCurrentGhostHealthPercent() const;
	
	UFUNCTION(BlueprintCallable, Category = "Ghost Bar UI")
	float GetCurrentGhostManaPercent() const;
	
	UFUNCTION(BlueprintCallable, Category = "Ghost Bar UI")
	float GetCurrentGhostHealth() const;
	
	UFUNCTION(BlueprintCallable, Category = "Ghost Bar UI")
	float GetCurrentGhostMana() const;

	//幽灵属性变化回调函数
	UFUNCTION()
	void OnGhostHealthChanged(float NewGhostHealth);
	
	UFUNCTION()
	void OnGhostManaChanged(float NewGhostMana);

	//当前属性变化回调函数
	UFUNCTION()
	void OnHealthChanged(float NewHealth);
	
	UFUNCTION()
	void OnManaChanged(float NewMana);
	
	UFUNCTION()
	void OnMaxHealthChanged(float NewMaxHealth);
	
	UFUNCTION()
	void OnMaxManaChanged(float NewMaxMana);

private:
	//静态变量定义
	static bool bGhostHealthBarFollowing;
	static bool bGhostManaBarFollowing;
	
	//当前显示的幽灵血球值
	float CurrentGhostHealth;
	//当前显示的幽灵法力球值
	float CurrentGhostMana;
	
	//目标幽灵血球值（从广播接收）
	float TargetGhostHealth;
	//目标幽灵法力球值（从广播接收）
	float TargetGhostMana;
	
	//当前生命值和法力值（用于跟随计算）
	float CurrentHealth;
	float CurrentMana;
	float MaxHealth;
	float MaxMana;
	
	//跟随速度（每秒移动的百分比）
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ghost Bar Settings", meta = (AllowPrivateAccess = "true"))
	float FollowSpeed = 2.0f; // 每秒移动2%的差值
	
	//更新幽灵血球显示
	void UpdateGhostHealthBar();
	//更新幽灵法力球显示
	void UpdateGhostManaBar();
}; 